home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: gail.ripco.com!mambuhl
- From: mambuhl@ripco.com (Martin Ambuhl)
- Subject: Re: Splitting String ?
- X-Nntp-Posting-Host: foley.ripco.com
- Message-ID: <DLA2BI.GsG@rci.ripco.com>
- Sender: usenet@rci.ripco.com (Net News Admin)
- Organization: Ripco Internet BBS Chicago
- Date: Tue, 16 Jan 1996 14:16:28 GMT
- X-Ident-Sender: mambuhl
-
- jatmon@iag.net (John R Buchan)
- in <4dbnpf$47c@news.iag.net> wrote:
-
- >In article <DL3u9M.9xt@rci.ripco.com>, mambuhl@ripco.com says...
- [snip]
- >->char *newname(char *s)
- >->{
- >->
- >-> char *dot;
- >-> dot = strchr(s, '.');
- >-> if (dot)
- >-> *dot = '\0';
- >-> strcat(s, ".UPD");
- >-> return s;
- >->}
-
- >Unless I'm misssing something, this isn't going to work (safely or maybe at
- >all), if he passes in the same string literals.
-
- Absolutely right. I didn't make at all clear the point I meant to make. As
- a result, I posted horrible code which is extremely dangerous. I
- promise to be more straight-forward in the future. In fact, as I
- re-read my message, I don't think I would have detected any irony.
- Sorry.
-
- The unstated point was that the above code is the same functionally as
- the originally posted code with a lot of stuff that masked what he was
- doing removed. Since the above code "does" exactly what the original
- code did and is clearly horrible, I thought it would be clear that he
- should rethink what he was doing.
-
- For those unclear about what is going on, when the above is called with
- a string literal, an attempt to change that literal is extremely
- dangerous since a) space has not been allocated and b) the literal need
- not be in writable memory.
-
- >->>main() {
- >->> printf("%s\n",newname("LONGNAME.TXT"));
- >->> printf("%s\n",newname("NOEND")); >->>}
-
-
- --
- * Martin Ambuhl net: mambuhl@ripco.com
- * Chicago, IL (USA)
-